﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;

public partial class JiGouManage_JgMain_update : Base
{
    Db List = new Db();
    BindDrowDownList list = new BindDrowDownList();
    public string LineW, QxString, QxStringSta, LineWSta;
    protected void Page_Load(object sender, EventArgs e)
    {
        string sQL = "select id,Linew+jgname as aaa  from qp_hr_JiGou order by paixu,QxString asc";
        if (!base.IsPostBack)
        {
            this.list.Bind_DropDownList_unit(this.ParentNodesID, sQL, "id", "aaa");
        }
        if (!this.Page.IsPostBack)
        {
            this.BindAttribute();
            string sql = "select * from qp_hr_JiGou where id='" + this.List.GetFormatStr(base.Request.QueryString["id"]) + "'";
            OleDbDataReader list = this.List.GetList(sql);
            if (list.Read())
            {
                this.Name.Text = list["JgName"].ToString();
                this.BianZhiS.Text = list["BianZhiS"].ToString();
                this.remark.Text = list["remark"].ToString();
                this.ParentNodesID.SelectedValue = list["ParentNodesID"].ToString();
                this.QxString1.Text = list["QxString"].ToString();
                this.txtPaiXu.Text = list["paixu"].ToString();
                this.ParentNodes.Text = list["ParentNodesID"].ToString();
            }
            list.Close();
        }


    }
    public void BindAttribute()
    {
        Button2.Attributes["onclick"] = "javascript:return showwait();";
        Button1.Attributes["onclick"] = "javascript:return chknull();";
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("JgMain.aspx?id=" + List.GetFormatStr(Request.QueryString["id"]) + "");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql = "select top 1 * from qp_hr_JiGou where id='" + this.ParentNodesID.SelectedValue + "' ";
        OleDbDataReader list = this.List.GetList(sql);
        if (list.Read())
        {
            this.QxStringSta = list["QxString"].ToString();
            this.LineWSta = list["LineW"].ToString();
        }
        list.Close();
        if (this.ParentNodesID.SelectedValue != this.ParentNodes.Text)
        {
            if (this.ParentNodesID.SelectedValue == "0")
            {
                string str2 = "select top 1 * from qp_hr_JiGou where ParentNodesID='0' order by QxString desc";
                OleDbDataReader reader2 = this.List.GetList(str2);
                if (reader2.Read())
                {
                    string str3 = "select  top 1 * from qp_hr_JiGouKey where id>(select  id  from qp_hr_JiGouKey where name='" + reader2["QxString"] + "') order by name asc";
                    OleDbDataReader reader3 = this.List.GetList(str3);
                    if (reader3.Read())
                    {
                        this.QxString = reader3["name"].ToString();
                        this.LineW = "|-";
                    }
                    else
                    {
                        this.QxString = "aaaaa";
                        this.LineW = "|-";
                    }
                    reader3.Close();
                }
                else
                {
                    this.QxString = "aaaaa";
                    this.LineW = "|-";
                }
                reader2.Close();
            }
            else
            {
                string str4 = "select  * from qp_hr_JiGou where id='" + this.ParentNodesID.SelectedValue + "'";
                OleDbDataReader reader4 = this.List.GetList(str4);
                if (reader4.Read())
                {
                    if (reader4["QxString"].ToString().Length == 5)
                    {
                        string str5 = "select  top 1 * from qp_hr_JiGou where  QxString like '%" + reader4["QxString"].ToString() + "%' and  len(QxString)=9 order by QxString desc";
                        OleDbDataReader reader5 = this.List.GetList(str5);
                        if (reader5.Read())
                        {
                            int num = int.Parse(reader5["QxString"].ToString().Substring(reader5["QxString"].ToString().Length - 4, 3)) + 1;
                            this.QxString = this.QxStringSta + num + "a";
                            this.LineW = "|---";
                        }
                        else
                        {
                            this.QxString = this.QxStringSta + "100a";
                            this.LineW = "|---";
                        }
                        reader5.Close();
                    }
                    else
                    {
                        string str7 = string.Concat(new object[] { "select  top 1 * from qp_hr_JiGou where  QxString like '%", reader4["QxString"].ToString(), "%' and  len(QxString)=", reader4["QxString"].ToString().Length, "+4 order by QxString desc" });
                        OleDbDataReader reader6 = this.List.GetList(str7);
                        if (reader6.Read())
                        {
                            int num2 = int.Parse(reader6["QxString"].ToString().Substring(reader6["QxString"].ToString().Length - 4, 3)) + 1;
                            this.QxString = this.QxStringSta + num2 + "a";
                            this.LineW = "|-";
                            for (int i = 0; i < (this.LineWSta.ToString().Length + 2); i++)
                            {
                                this.LineW = this.LineW + "-";
                            }
                        }
                        else
                        {
                            string str9 = string.Concat(new object[] { "select  top 1 * from qp_hr_JiGou where  QxString like '%", reader4["QxString"].ToString().Substring(0, reader4["QxString"].ToString().Length - 4), "%' and  len(QxString)=", reader4["QxString"].ToString().Length, " order by QxString desc" });
                            if (this.List.GetList(str9).Read())
                            {
                                this.QxString = this.QxStringSta + "100a";
                                this.LineW = "|-";
                                for (int j = 0; j < (this.LineWSta.ToString().Length + 2); j++)
                                {
                                    this.LineW = this.LineW + "-";
                                }
                            }
                        }
                        reader6.Close();
                    }
                }
                reader4.Close();
            }
            string str10 = string.Concat(new object[] { "Update qp_hr_JiGou  Set JgName='", this.List.GetFormatStr(this.Name.Text), "',remark='", this.List.GetFormatStr(this.remark.Text), "',ParentNodesID='", this.ParentNodesID.SelectedValue, "',LineW='", this.LineW, "',QxString='", this.QxString, "',paixu='", this.txtPaiXu.Text, "'  where id='", int.Parse(base.Request.QueryString["id"]), "'" });
            this.List.ExeSql(str10);
        }
        else
        {
            string str11 = string.Concat(new object[] { "Update qp_hr_JiGou  Set JgName='", this.List.GetFormatStr(this.Name.Text), "',BianZhiS='", this.BianZhiS.Text, "',paixu='", this.txtPaiXu.Text, "',remark='", this.List.GetFormatStr(this.remark.Text), "' where id='", int.Parse(base.Request.QueryString["id"]), "'" });
            this.List.ExeSql(str11);
        }
        this.List.InsertLog("修改部门[" + this.Name.Text + "]", "部门管理");
        base.Response.Write("<script language=javascript>alert('提交成功！'); window.location = 'JgMain.aspx?id=" + base.Request.QueryString["id"] + "'</script>");
    }
}
